layui.use(['form','layer','table','laytpl'],function() {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laytpl = layui.laytpl,
        table = layui.table;

    var tableIns3 = table.render({
        elem: "#userlist3",
        url: 'http://101.201.56.140:10086/pc/InspectStandard/selAll',
        cellMinWidth: 95,
        page: true,
        height: "full-125",
        limits: [10, 15, 20, 25],
        limit: 10,
        id: "userListTable3",
        cols: [[
            {type: "checkbox", fixed: "left", width: 50},
            {field: 'inspectStandardID', title: '检验标准ID', align: 'center',width: 100},
            {field: 'inspectTypeID', title: '检验类型ID', minWidth: 100, align: "center", templet:function (d) {


                }},
            {
                field: 'inspectStandardClass', title: '检验分类',width:100, align: 'center', templet: function (d) {
                    if (d.inspectStandardClass == "0") {
                        return "质量";
                    } else if (d.inspectStandardClass == "1") {
                        return "安全";
                    }
                }
            },
            {field: 'inspectStandardName', title: '检验标准名称', align: 'center', width: 150},
            {field: 'inspectStandardContent', title: '检验标准内容', align: 'center', width: 200,},
            {field: 'lowVersionID', title: '低版本', align: 'center'},
            {field: 'highVersionID', title: '高版本', align: 'center'},
            {title: '子项及其版本',fixed:'right', align: 'center', templet: '#version', width: 200},

            {title: '操作', minWidth: 150, templet: '#userListBar', fixed: "right", align: "center"}
        ]]

    })


    //搜索【此功能需要后台配合，所以暂时没有动态效果演示】
    $(".search_btn").click(function () {
        var inputVal = $('.layui-input ').val();

        table.reload('userListTable', {

            url: 'http://101.201.56.140:10086/pc/InspectStandard/selByID',
            method: 'post',
            request: {
                statusName: 'status',
                // pageName:'pageNum',
                // limitName: 'pageSize'
            },
            where: {
                inspectTypeID: inputVal,
                status: 0

            },
            page: {
                curr: 1
            }

        })
    })

    //标准子项
    function InspectStandard() {
        var index = layui.layer.open({
            title: "标准子项",
            type: 2,
            content: "../btn in list/StandardLine.html",
            success: function (layero, index) {
                var body = layui.layer.getChildFrame('body', index);
                setTimeout(function () {
                    layui.layer.tips('点击此处返回标准列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        })
        layui.layer.full(index);
        window.sessionStorage.setItem("index", index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(window.sessionStorage.getItem("index"));
        })
    }

    //相关版本
    function AV() {
        var index = layui.layer.open({
            title: "相关版本",
            type: 2,
            content: "../btn in list/Aversion.html",
            success: function (layero, index) {
                var body = layui.layer.getChildFrame('body', index);
                setTimeout(function () {
                    layui.layer.tips('点击此处返回标准列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        })
        layui.layer.full(index);
        window.sessionStorage.setItem("index", index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(window.sessionStorage.getItem("index"));
        })
    }




    //添加标准
    function addUser(edit) {
        var index = layui.layer.open({
            title: "添加类型",
            type: 2,
            content: "../dataAdd/StandardAdd.html",
            success: function (layero, index) {
                var body = layui.layer.getChildFrame('body', index);
                if (edit) {
                    body.find(".Sname").val(edit.Sname);  //检验标准名称
                    body.find(".testClassify").val(edit.version);  //启用版本
                    body.find(".testDepict").text(edit.testClassify);    //检验分类
                    body.find(".testType").text(edit.testType); //检验类型
                    body.find(".SContent").val(edit.SContent); //标准内容

                    form.render();
                }
                setTimeout(function () {
                    layui.layer.tips('点击此处返回标准列表', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                }, 500)
            }
        })
        layui.layer.full(index);
        window.sessionStorage.setItem("index", index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize", function () {
            layui.layer.full(window.sessionStorage.getItem("index"));
        })
    }


    $(".addNews_btn").click(function () {
        addUser();
    })

    //批量删除
    $(".delAll_btn").click(function () {
        var checkStatus = table.checkStatus('userListTable'),
            data = checkStatus.data,
            newsId = [];
        if (data.length > 0) {
            for (var i in data) {
                newsId.push(data[i].newsId);
            }
            layer.confirm('确定删除选中的标准？', {icon: 3, title: '提示信息'}, function (index) {
                $.post("http://101.201.56.140:10086/pc/InspectStandard/deletes",{
                    newsId : newsId  //将需要删除的newsId作为参数传入
                },function(data){

                layer.close(index);

                })
            })
        } else {
            layer.msg("请选择需要删除的标准");
        }
    })

    //列表操作
    table.on('tool(userlist3)', function (obj) {
        var data = obj.data;
        switch (obj.event) {
            case 'edit':
               AV(data)
                break;

            case 'del':
                layer.confirm('确定删除此标准？', {icon: 3, title: '提示信息'}, function (index) {
                    $.post({
                        datatype: 'json',
                        url: 'http://101.201.56.140:10086/pc/InspectStandard/delete',
                        data: {'inspectStandardID': data.inspectStandardID},
                    })
                    obj.del();
                    layer.close(index);
                })
                break;
            case 'detail':
                InspectStandard(data);
                break;
            case 'Aversion':
                AV(data);
                break;

        }
    })
})







